Display (1) function

I have a print file that is begin pollinated by

Display (1)
‘field1’ #field1
‘field2’ #field2

I need to display ‘Listing A:’ only once before the fields are display.
I will be grateful if somebody could tel me if this will work

Display (1) ‘Listing A:’ /
‘field1’ #field1
‘field2’ #field2

You already know that this doesn’t work, because when you tried it yourself,

DEFINE DATA LOCAL
1 #FLD1 (A5)   INIT <'AbCdE'>
1 #FLD2 (N5.2) INIT <-12345.67>
END-DEFINE
DISPLAY 'Listing A' / 'Field 1' #FLD1
        'Field 2' #FLD2
END

you saw

Page     1                                                   02/20/19  07:49:48
 
 Field 1   Field 2
--------- ----------
 
Listing A -12345.67
AbCdE

In the report above, lines 1 and 2 are the report title and lines 3, 4, and 5 are the report header. You can place additional lines between those two sections with AT TOP OF PAGE. So, there are three solutions.

Solution 1 - Report Title

DEFINE DATA LOCAL
1 #FLD1 (A5)   INIT <'AbCdE'>
1 #FLD2 (N5.2) INIT <-12345.67>
END-DEFINE
DISPLAY 'Field 1' #FLD1
        'Field 2' #FLD2
*
WRITE TITLE LEFT 'Listing A' /
END
Listing A
 
Field 1  Field 2
------- ---------
 
AbCdE   -12345.67

Solution 2 - Report Header

DEFINE DATA LOCAL
1 #GRP                            (HD='Listing A')
  2 #FLD1 (A5)   INIT <'AbCdE'>   (HD='Field 1')
  2 #FLD2 (N5.2) INIT <-12345.67> (HD='Field 1')
END-DEFINE
DISPLAY #GRP
END
Page     1                                                   02/20/19  08:03:33
 
    Listing A
 
Field 1  Field 1
------- ---------
 
AbCdE   -12345.67

Solution 3 - At Top of Page

DEFINE DATA LOCAL
1 #FLD1 (A5)   INIT <'AbCdE'>
1 #FLD2 (N5.2) INIT <-12345.67>
END-DEFINE
DISPLAY 'Field 1' #FLD1
        'Field 2' #FLD2
*
AT TOP OF PAGE
WRITE 'Listing A' /
END-TOPPAGE
END
Page     1                                                   02/20/19  08:07:18
 
Listing A
 
Field 1  Field 2
------- ---------
 
AbCdE   -12345.67

If you really want ‘Listing A’ to appear only once, not at the top of each page, then add a switch.

DEFINE DATA LOCAL
1 #FLD1 (A5)   INIT <'AbCdE'>
1 #FLD2 (N5.2) INIT <-12345.67>
1 #ONCE (L)    INIT <TRUE>
1 #I (I4)
END-DEFINE
FORMAT PS=10
*
FOR #I = 1 5
  DISPLAY #I
          'Field 1' #FLD1
          'Field 2' #FLD2
END-FOR
*
AT TOP OF PAGE
IF  #ONCE
  THEN
    WRITE 'Listing A' /
END-IF
RESET #ONCE
END-TOPPAGE
END
Page     1                                                   02/20/19  08:13:21
 
Listing A
 
    #I      Field 1  Field 2
----------- ------- ---------
 
          1 AbCdE   -12345.67
          2 AbCdE   -12345.67
          3 AbCdE   -12345.67
Page     2                                                   02/20/19  08:13:21
 
    #I      Field 1  Field 2
----------- ------- ---------
 
          4 AbCdE   -12345.67
          5 AbCdE   -12345.67

or, if you just want “Listing A” once -


DEFINE DATA LOCAL  
1 #FLD1 (A5)   INIT <'AbCdE'>  
1 #FLD2 (N5.2) INIT <-12345.67>  
1 #I (I4)  
END-DEFINE  
FORMAT PS=10  
*
WRITE 'Listing A' /  
*  
FOR #I = 1 5  
  DISPLAY #I  
          'Field 1' #FLD1  
          'Field 2' #FLD2  
END-FOR  
*  
END  

No switch needed. Depends on what you really need to do…