?? RIGHT := 110 ??
MODULE ocm$open_scratch_segment;
*copyc osd$default_pragmats
?? PUSH (LISTEXT := ON) ??
*copyc ost$status
*copyc clp$scan_command_line
*copyc pmp$get_unique_name
*copyc amp$open
*copyc amp$get_segment_pointer
*copyc pmp$abort
?? POP ??
*copyc och$open_scratch_segment

  PROCEDURE [XDCL] ocp$open_scratch_segment (scl_var: string (31);
    VAR fid: amt$file_identifier;
    VAR seg_p: amt$segment_pointer;
    VAR status: ost$status);

    VAR
      access_sel: amt$file_access_selections,
      create_var: string (osc$max_string_size),
      length: integer,
      name: ost$name;

    pmp$get_unique_name (name, status);
    IF NOT status.normal THEN
      pmp$abort (status);
    IFEND;
    STRINGREP (create_var, length, ' create_variable n=', scl_var, ' k=string s=job v=''', name, '''');
    clp$scan_command_line (create_var (1, length), status);
    IF NOT status.normal AND (status.condition <> cle$var_already_created) THEN
      pmp$abort (status);
    IFEND;
    PUSH access_sel: [1 .. 2];
    access_sel^ [1].key := amc$access_mode;
    access_sel^ [1].access_mode := $pft$usage_selections [pfc$read, pfc$shorten, pfc$append, pfc$modify];
    access_sel^ [2].key := amc$return_option;
    access_sel^ [2].return_option := amc$return_at_close;
    amp$open (name, amc$segment, access_sel, fid, status);
    IF NOT status.normal THEN
      pmp$abort (status);
    IFEND;
    amp$get_segment_pointer (fid, amc$sequence_pointer, seg_p, status);
    IF NOT status.normal THEN
      pmp$abort (status);
    IFEND;
  PROCEND ocp$open_scratch_segment;
MODEND ocm$open_scratch_segment;
