2008 Sep 19 9:37 PM
Hi,
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?
Thanks,
Gregg
2008 Sep 19 10:07 PM
Hi,
Try this...
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.
Thanks
Naren
2008 Sep 19 10:07 PM
Hi,
Try this...
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.
Thanks
Naren
2008 Sep 22 12:22 AM
Hi Naren,
Thank you for your response. Your suggestion would certainly work and it would not use any obsolete syntax. However I was hoping for a solution using the ASSIGN ... INCREMENTING syntax that SAP seems to be suggesting for a replacement to the DO ... VARYING syntax now that they have marked it as obsolete. It may very well be that your solution is the only non-obsolete option for my situation since I have a 2 field repeating structure and all the examples that I found in SAP Help that use the ASSIGN ... INCREMENTING syntax were single field repeating structures. I will award you with points since you did come up with a solution that meets the criteria of the question. However, I will leave this question open for a little bit longer in case someone else can come up with a solution using the ASSIGN ... INCREMENTING syntax for a two field repetitive structure. Thank you again for you response.
Regards,
Gregg
2008 Sep 22 5:34 PM
Hi,
Try this code...as per the new syntax..
TYPES: BEGIN OF ls_dep_struc,
dty TYPE ben_deptyp,
did TYPE ben_depid,
END OF ls_dep_struc.
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.
INCLUDE TYPE: ls_dep_struc AS comp1 RENAMING WITH SUFFIX 01,
ls_dep_struc AS comp2 RENAMING WITH SUFFIX 02,
ls_dep_struc AS comp3 RENAMING WITH SUFFIX 03,
ls_dep_struc AS comp4 RENAMING WITH SUFFIX 04,
ls_dep_struc AS comp5 RENAMING WITH SUFFIX 05,
ls_dep_struc AS comp6 RENAMING WITH SUFFIX 06,
ls_dep_struc AS comp7 RENAMING WITH SUFFIX 07,
ls_dep_struc AS comp8 RENAMING WITH SUFFIX 08,
ls_dep_struc AS comp9 RENAMING WITH SUFFIX 09,
ls_dep_struc AS comp10 RENAMING WITH SUFFIX 10,
ls_dep_struc AS comp11 RENAMING WITH SUFFIX 11,
ls_dep_struc AS comp12 RENAMING WITH SUFFIX 12.
DATA: END OF ls_outtab.
FIELD-SYMBOLS <sub> TYPE ls_dep_struc.
DATA inc TYPE i.
WHILE sy-subrc = 0.
inc = sy-index - 1.
ASSIGN ls_outtab-comp1 INCREMENT inc TO <sub> CASTING
RANGE ls_outtab.
IF sy-subrc = 0.
WRITE:/ <sub>-dty, <sub>-did.
ENDIF.
ENDWHILE.
Thanks
Naren