Reading repetitive structures in a non-obsolete manner
I need to read data from a repetitive structure. I have done this many times before in a an older version of SAP using the
DO xx TIMES VARYING structure FROM field_01 NEXT field_02
technique. We recently upgraded to Netweaver 7.0 and I notice that the VARYING addition of the DO statement is now marked as obsolete. Yes, I can still use it, but I prefer to read the structure in a non-obsolete manner. According to the SAP Help, the preferred method of reading a repetitive structure is now using the ASSIGN statement with the INCREMENT option. I tried to change my coding using the new approach, but it comes back with a syntax error because of my situation. The repetitive structure that I need to read has a 2 field repeating structure (the same type of situation that is found in PA0041 or PA0167). Following are my structures:
DATA: BEGIN OF LS_OUTTAB, INFTY TYPE INFTY, ZZLOADID TYPE ZZLOADID, PERNR TYPE PERNR_D, ENDDA TYPE ENDDA, BEGDA TYPE BEGDA, PLTYP TYPE BEN_TYPE, BPLAN TYPE BEN_PLAN, BOPTI TYPE BEN_OPTION, DEPCV TYPE BEN_DEPCOV, PARDT TYPE BEN_PARTDT, DTY01 TYPE BEN_DEPTYP, DID01 TYPE BEN_DEPID, DTY02 TYPE BEN_DEPTYP, DID02 TYPE BEN_DEPID, DTY03 TYPE BEN_DEPTYP, DID03 TYPE BEN_DEPID, DTY04 TYPE BEN_DEPTYP, DID04 TYPE BEN_DEPID, ... ... DTY19 TYPE BEN_DEPTYP, DID19 TYPE BEN_DEPID, DTY20 TYPE BEN_DEPTYP, DID20 TYPE BEN_DEPID, END OF LS_OUTTAB. DATA: BEGIN OF LS_DEP_STRUC, DTY TYPE BEN_DEPTYP, DID TYPE BEN_DEPID, END OF LS_DEP_STRUC.
I can successfully read the repetitive data structure using the old obsolete way:
DO 20 TIMES VARYING ls_dep_struc FROM LS_OUTTAB-dty01 NEXT LS_OUTTAB-dty02 RANGE LS_OUTTAB. ENDDO.
I created the following code trying to read it using the new technique:
FIELD-SYMBOLS: <fs_dep_struc> LIKE LS_DEP_STRUC. WHILE sy-subrc = 0. lv_inc = sy-index - 1. ASSIGN LS_OUTTAB-dty01 INCREMENT lv_inc TO <fs_dep_struc> CASTING RANGE ls_dep_struc. IF sy-subrc = 0. ENDIF. ENDWHILE.
But I received a syntax message saying:
"LS_OUTTAB-DTY01" is too short for "<FS_DEP_STRUC>".
The problem is that I do not know how to reference 2 fields as the memory area of the ASSIGN statement in order to assign to my field symbol. I tried using offset and lengths in the memory area
ASSIGN LS_OUTTAB+60(6) INCREMENT lv_inc TO <fs_dep_struc> CASTING RANGE ls_dep_struc.
But I get a syntax error saying:
You cannot use offset/length addressing in the INCREMENT addition for "LS_OUTTAB-DTY01".
Does anyone have a way to read a two field repetitive structure without using the obsolete option VARYING on the DO command?
Narendran Muthukumaran replied
You can declare two field symbols...
FIELD-SYMBOLS: <fs1>, <fs2>. DATA: v_index TYPE numc2. DATA: fieldname TYPE char30. DO 20 TIMES. v_index = v_index + 1. * DTY Field CONCATENATE 'DTY' v_index INTO fieldname. CONDENSE fieldname. ASSIGN COMPONENT fieldname OF STRUCTURE ls_outtab TO <fs1>. CHECK sy-subrc = 0. * DID Field CONCATENATE 'DID' v_index INTO fieldname. CONDENSE fieldname. ASSIGN COMPONENT fieldname OF STRUCTURE ls_outtab TO <fs2>. CHECK sy-subrc = 0. **Here you can access the field-symbol <FS1> & <FS2> ls_dep_struc-dty = <fs1>. ls_dep_struc-did = <fs2>. ENDDO.