2008 Sep 26 8:07 PM
Hi,
Below is a snippet of my code
DATA: ls_data_package LIKE LINE OF DATA_PACKAGE[].
FIELD-SYMBOLS:<ls_data_package> LIKE LINE OF DATA_PACKAGE[].
zbib_sysn_temp = <ls_data_package>-/bic/zbib_sysn+off3(off4).
<ls_data_package>-/bic/zd_user = <ls_data_package>-/bic/zbib_sysn(off).
<ls_data_package>-/bic/zwrk = <ls_data_package>-/bic/zbib_sysn+off1.
I want to insert a new line to the data package, with all the fields same while adding the above two,
except for,
<ls_data_package>-/bic/zd_user = zbib_sysn_temp
<ls_data_package>-/bic/zitm = 2.
Note: by default the field /bic/zitm = 1. So while adding for the 1st time it is set to 1 by default. I want to add a second (new line) to the datapackage which has all fields same except for the /bic/zd_user and the /bic/zitm = 2.
Please help me with this code,
CD
2008 Sep 26 9:13 PM
Does this help...
TYPES:
BEGIN OF x_data,
f1 TYPE i,
f2 TYPE c LENGTH 6,
END OF x_data.
DATA: i_data TYPE STANDARD TABLE OF x_data INITIAL SIZE 0,
wa_data TYPE x_data,
counter TYPE i.
FIELD-SYMBOLS: <f1> TYPE x_data.
ASSIGN wa_data TO <f1>.
wa_data-f1 = 1.
wa_data-f2 = 'Test'.
DO 5 TIMES.
counter = counter + 1.
<f1>-f1 = counter.
<f1>-f2 = 'Test' .
APPEND <f1> TO i_data.
ENDDO.
BREAK-POINT.
2008 Sep 26 9:13 PM
Does this help...
TYPES:
BEGIN OF x_data,
f1 TYPE i,
f2 TYPE c LENGTH 6,
END OF x_data.
DATA: i_data TYPE STANDARD TABLE OF x_data INITIAL SIZE 0,
wa_data TYPE x_data,
counter TYPE i.
FIELD-SYMBOLS: <f1> TYPE x_data.
ASSIGN wa_data TO <f1>.
wa_data-f1 = 1.
wa_data-f2 = 'Test'.
DO 5 TIMES.
counter = counter + 1.
<f1>-f1 = counter.
<f1>-f2 = 'Test' .
APPEND <f1> TO i_data.
ENDDO.
BREAK-POINT.
2008 Sep 26 9:23 PM
Souvrav, thanks for the reply.
I am not an ABAP'er, I have managed to write code so far. Can you please help me with how this can be done in this code:
DATA: off, off1, off2, off3, off4, off5, off6 TYPE i.
DATA: zbib_sysn_temp TYPE string.
DATA: ls_data_package LIKE LINE OF DATA_PACKAGE[].
FIELD-SYMBOLS:<ls_data_package> LIKE LINE OF DATA_PACKAGE[].
SORT DATA_PACKAGE BY /bic/zbib_id.
LOOP AT DATA_PACKAGE ASSIGNING <ls_data_package>.
IF <ls_data_package>-/bic/zbib_sysn IS NOT INITIAL.
TRANSLATE <ls_data_package>-/bic/zbib_sysn TO UPPER CASE.
FIND '/' IN <ls_data_package>-/bic/zbib_sysn MATCH OFFSET off2.
zbib_sysn_temp = <ls_data_package>-/bic/zbib_sysn+off3(off4).
IF sy-subrc EQ 0.
<ls_data_package>-/bic/zd_user =
<ls_data_package>-/bic/zbib_sysn(off).
Now at this point of code i want to copy this existing record from ls_data_package to create a new record where /bic/zd_user = zbib_sysn_temp and /bic/zitm = 2.
Pleas help...
2008 Sep 26 9:57 PM
DATA: off, off1, off2, off3, off4, off5, off6 TYPE i.
DATA: zbib_sysn_temp TYPE string.
" Declare a temporary internal table
DATA: DATA_PACKAGE1 like DATA_PACKAGE.
DATA: ls_data_package LIKE LINE OF DATA_PACKAGE[].
FIELD-SYMBOLS:<ls_data_package> LIKE LINE OF DATA_PACKAGE[].
SORT DATA_PACKAGE BY /bic/zbib_id.
LOOP AT DATA_PACKAGE ASSIGNING <ls_data_package>.
IF <ls_data_package>-/bic/zbib_sysn IS NOT INITIAL.
TRANSLATE <ls_data_package>-/bic/zbib_sysn TO UPPER CASE.
FIND '/' IN <ls_data_package>-/bic/zbib_sysn MATCH OFFSET off2.
zbib_sysn_temp = <ls_data_package>-/bic/zbib_sysn+off3(off4).
IF sy-subrc EQ 0.
<ls_data_package>-/bic/zd_user = <ls_data_package>-/bic/zbib_sysn(off).
" Populate /bic/zitm as per your logic
<ls_data_package>-/bic/zitm = '2'.
"Never append the same internal table you are looping, it will go for a infinite loop
append <ls_data_package> to DATA_PACKAGE1.
enloop.
2008 Sep 26 10:00 PM
Souvrav, can you please provide me the code. I am nt an ABAP'er and having a real hard time to incorporate this logic.
Please help,,
CD
2008 Sep 26 10:15 PM
Don't know your exact logic...so its very difficult to code...but try this:
Do you really wanna add just a single record in the internal table DATA_PACKAGE?
DATA: off, off1, off2, off3, off4, off5, off6 TYPE i.
DATA: zbib_sysn_temp TYPE string.
DATA: ls_data_package LIKE LINE OF DATA_PACKAGE[].
FIELD-SYMBOLS:<ls_data_package> LIKE LINE OF DATA_PACKAGE[].
SORT DATA_PACKAGE BY /bic/zbib_id.
" This will work only when DATA_PACKAGE ASSIGNING has a single record
Read table DATA_PACKAGE ASSIGNING <ls_data_package> index 1.
IF sy-subrc = 0 and <ls_data_package>-/bic/zbib_sysn IS NOT INITIAL.
TRANSLATE <ls_data_package>-/bic/zbib_sysn TO UPPER CASE.
FIND '/' IN <ls_data_package>-/bic/zbib_sysn MATCH OFFSET off2.
zbib_sysn_temp = <ls_data_package>-/bic/zbib_sysn+off3(off4).
<ls_data_package>-/bic/zd_user = <ls_data_package>-/bic/zbib_sysn(off).
IF sy-subrc EQ 0.
<ls_data_package>-/bic/zitm = '2'.
append <ls_data_package> to DATA_PACKAGE.
"now DATA_PACKAGE should have two records
endif.
endif.