ABAP Select data from SAP table PS3330 into internal table
Get Example source ABAP code based on a different SAP table
Below is a number of ABAP code snippets to demonstrate how to select data from SAP PS3330 table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to PS3330. See here for more generic Select statement tips.
Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.
There is also a full declaration of the PS3330 table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.
DATA: IT_PS3330 TYPE STANDARD TABLE OF PS3330, WA_PS3330 TYPE PS3330, GD_STR TYPE STRING. DATA: lo_typedescr type REF TO cl_abap_typedescr. DATA: lv_fieldname type fieldname. FIELD-SYMBOLS: <FIELD> TYPE any. FIELD-SYMBOLS: <PS3330> TYPE PS3330. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_PS3330. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM PS3330 INTO TABLE IT_PS3330. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM PS3330 * INTO TABLE @DATA(IT_PS33302). *--Further methods of using ABAP code to select data from SAP database tables *You can also declare the header/work area using the in-line DATA declaration method READ TABLE IT_PS3330 INDEX 1 INTO DATA(WA_PS33302). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_PS3330 ASSIGNING <PS3330>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<PS3330>-SUBRE = 1.
<PS3330>-LNCOD = 1.
<PS3330>-PLNCD = 1.
<PS3330>-DPFLG = 1.
<PS3330>-LNDAT = 1.
ENDLOOP. LOOP AT IT_PS3330 INTO WA_PS3330. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_PS3330-LOGRN, sy-vline,
WA_PS3330-REAS1, sy-vline,
WA_PS3330-REAS2, sy-vline,
WA_PS3330-REAS3, sy-vline,
WA_PS3330-PARCD, sy-vline,
WA_PS3330-DATE1, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PS3330 you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_PS3330 TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_PS3330 INTO WA_PS3330. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_PS3330_STR,
SUBRE TYPE STRING,
LNCOD TYPE STRING,
PLNCD TYPE STRING,
DPFLG TYPE STRING,
LNDAT TYPE STRING,
LOGRN TYPE STRING,
REAS1 TYPE STRING,
REAS2 TYPE STRING,
REAS3 TYPE STRING,
PARCD TYPE STRING,
DATE1 TYPE STRING,
DATE2 TYPE STRING,
VONUM TYPE STRING,
VOGRN TYPE STRING,
SRVS1 TYPE STRING,
SRVO1 TYPE STRING,
SRVD1 TYPE STRING,
SRVN1 TYPE STRING,
SRVS2 TYPE STRING,
SRVO2 TYPE STRING,
SRVD2 TYPE STRING,
SRVN2 TYPE STRING,
ERFLG TYPE STRING,
HSDT1 TYPE STRING,
HSDT2 TYPE STRING,
HSBRC TYPE STRING,
HSBRD TYPE STRING,
MSED1 TYPE STRING,
MSED2 TYPE STRING,
MSED3 TYPE STRING,
MSEIG TYPE STRING,
MSERS TYPE STRING,
T1DT1 TYPE STRING,
T1DT2 TYPE STRING,
T1DPN TYPE STRING,
T1DNM TYPE STRING,
T1DID TYPE STRING,
T1D2P TYPE STRING,
T1CNM TYPE STRING,
T1D2I TYPE STRING,
T2DT1 TYPE STRING,
T2DT2 TYPE STRING,
T2DPN TYPE STRING,
T2DNM TYPE STRING,
T2DID TYPE STRING,
T2D2P TYPE STRING,
T2CNM TYPE STRING,
T2D2I TYPE STRING,
T3DT1 TYPE STRING,
T3DT2 TYPE STRING,
T3DPN TYPE STRING,
T3DNM TYPE STRING,
T3DID TYPE STRING,
T3D2P TYPE STRING,
T3CNM TYPE STRING,
T3D2I TYPE STRING,
OSTDT TYPE STRING,
RETDT TYPE STRING,
NXTCD TYPE STRING,
N1DAT TYPE STRING,
KTEXT_SEQNR_L TYPE STRING,
KTEXT_SEQNR_V TYPE STRING,
ELNTY TYPE STRING,
CNGLN TYPE STRING,END OF T_EKKO_STR. DATA: WA_PS3330_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_PS3330_STR-SUBRE sy-vline
WA_PS3330_STR-LNCOD sy-vline
WA_PS3330_STR-PLNCD sy-vline
WA_PS3330_STR-DPFLG sy-vline
WA_PS3330_STR-LNDAT sy-vline
WA_PS3330_STR-LOGRN sy-vline
WA_PS3330_STR-REAS1 sy-vline
WA_PS3330_STR-REAS2 sy-vline
WA_PS3330_STR-REAS3 sy-vline
WA_PS3330_STR-PARCD sy-vline
WA_PS3330_STR-DATE1 sy-vline
WA_PS3330_STR-DATE2 sy-vline
WA_PS3330_STR-VONUM sy-vline
WA_PS3330_STR-VOGRN sy-vline
WA_PS3330_STR-SRVS1 sy-vline
WA_PS3330_STR-SRVO1 sy-vline
WA_PS3330_STR-SRVD1 sy-vline
WA_PS3330_STR-SRVN1 sy-vline
WA_PS3330_STR-SRVS2 sy-vline
WA_PS3330_STR-SRVO2 sy-vline
WA_PS3330_STR-SRVD2 sy-vline
WA_PS3330_STR-SRVN2 sy-vline
WA_PS3330_STR-ERFLG sy-vline
WA_PS3330_STR-HSDT1 sy-vline
WA_PS3330_STR-HSDT2 sy-vline
WA_PS3330_STR-HSBRC sy-vline
WA_PS3330_STR-HSBRD sy-vline
WA_PS3330_STR-MSED1 sy-vline
WA_PS3330_STR-MSED2 sy-vline
WA_PS3330_STR-MSED3 sy-vline
WA_PS3330_STR-MSEIG sy-vline
WA_PS3330_STR-MSERS sy-vline
WA_PS3330_STR-T1DT1 sy-vline
WA_PS3330_STR-T1DT2 sy-vline
WA_PS3330_STR-T1DPN sy-vline
WA_PS3330_STR-T1DNM sy-vline
WA_PS3330_STR-T1DID sy-vline
WA_PS3330_STR-T1D2P sy-vline
WA_PS3330_STR-T1CNM sy-vline
WA_PS3330_STR-T1D2I sy-vline
WA_PS3330_STR-T2DT1 sy-vline
WA_PS3330_STR-T2DT2 sy-vline
WA_PS3330_STR-T2DPN sy-vline
WA_PS3330_STR-T2DNM sy-vline
WA_PS3330_STR-T2DID sy-vline
WA_PS3330_STR-T2D2P sy-vline
WA_PS3330_STR-T2CNM sy-vline
WA_PS3330_STR-T2D2I sy-vline
WA_PS3330_STR-T3DT1 sy-vline
WA_PS3330_STR-T3DT2 sy-vline
WA_PS3330_STR-T3DPN sy-vline
WA_PS3330_STR-T3DNM sy-vline
WA_PS3330_STR-T3DID sy-vline
WA_PS3330_STR-T3D2P sy-vline
WA_PS3330_STR-T3CNM sy-vline
WA_PS3330_STR-T3D2I sy-vline
WA_PS3330_STR-OSTDT sy-vline
WA_PS3330_STR-RETDT sy-vline
WA_PS3330_STR-NXTCD sy-vline
WA_PS3330_STR-N1DAT sy-vline
WA_PS3330_STR-KTEXT_SEQNR_L sy-vline
WA_PS3330_STR-KTEXT_SEQNR_V sy-vline
WA_PS3330_STR-ELNTY sy-vline
WA_PS3330_STR-CNGLN sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.