ABAP Select data from SAP table PS0968 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 PS0968 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 PS0968. 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 PS0968 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_PS0968 TYPE STANDARD TABLE OF PS0968, WA_PS0968 TYPE PS0968, 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: <PS0968> TYPE PS0968. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_PS0968. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM PS0968 INTO TABLE IT_PS0968. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM PS0968 * INTO TABLE @DATA(IT_PS09682). *--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_PS0968 INDEX 1 INTO DATA(WA_PS09682). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_PS0968 ASSIGNING <PS0968>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<PS0968>-EMETH = 1.
<PS0968>-EFILE = 1.
<PS0968>-SSTAT = 1.
<PS0968>-CSTAT = 1.
<PS0968>-TIPOP = 1.
ENDLOOP. LOOP AT IT_PS0968 INTO WA_PS0968. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_PS0968-CDLUG, sy-vline,
WA_PS0968-CNTRT, sy-vline,
WA_PS0968-TRFCO, sy-vline,
WA_PS0968-DIREC, sy-vline,
WA_PS0968-VIAKM, sy-vline,
WA_PS0968-OTROC, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PS0968 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_PS0968 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_PS0968 INTO WA_PS0968. *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.
*Conversion exit PESDA, internal->external for field CDAGE CALL FUNCTION 'CONVERSION_EXIT_PESDA_OUTPUT' EXPORTING input = WA_PS0968-CDAGE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PS0968-CDAGE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit PESDA, internal->external for field AGENT CALL FUNCTION 'CONVERSION_EXIT_PESDA_OUTPUT' EXPORTING input = WA_PS0968-AGENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PS0968-AGENT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit PESDA, internal->external for field AGENM CALL FUNCTION 'CONVERSION_EXIT_PESDA_OUTPUT' EXPORTING input = WA_PS0968-AGENM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PS0968-AGENM.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_PS0968_STR,
EMETH TYPE STRING,
EFILE TYPE STRING,
SSTAT TYPE STRING,
CSTAT TYPE STRING,
TIPOP TYPE STRING,
CDLUG TYPE STRING,
CNTRT TYPE STRING,
TRFCO TYPE STRING,
DIREC TYPE STRING,
VIAKM TYPE STRING,
OTROC TYPE STRING,
MUNIC TYPE STRING,
PROVN TYPE STRING,
CPAIS TYPE STRING,
CEMP2 TYPE STRING,
CTEP2 TYPE STRING,
CIFTY TYPE STRING,
CIFCO TYPE STRING,
RAZON TYPE STRING,
DMCIL TYPE STRING,
CPROV TYPE STRING,
CPOST TYPE STRING,
CTELE TYPE STRING,
CPLAN TYPE STRING,
FECAC TYPE STRING,
FECBA TYPE STRING,
HORAA TYPE STRING,
HTRAB TYPE STRING,
HABIT TYPE STRING,
EVALU TYPE STRING,
ADES1 TYPE STRING,
ADES2 TYPE STRING,
LUGAR TYPE STRING,
CDTRA TYPE STRING,
ESPEC TYPE STRING,
CDAGE TYPE STRING,
CDDES TYPE STRING,
AGENT TYPE STRING,
TPMOD TYPE STRING,
CDCON TYPE STRING,
AGENM TYPE STRING,
MULTI TYPE STRING,
TESTI TYPE STRING,
DATTE TYPE STRING,
CDLES TYPE STRING,
GRADO TYPE STRING,
CDPAR TYPE STRING,
MDNOM TYPE STRING,
MDDOM TYPE STRING,
MDTEL TYPE STRING,
ASIST TYPE STRING,
CDHOS TYPE STRING,
HOSPI TYPE STRING,
EPLAN TYPE STRING,
DTCCC TYPE STRING,
DCNAC TYPE STRING,
CDCNO TYPE STRING,
FENOM TYPE STRING,
FECAL TYPE STRING,
FEPRO TYPE STRING,
WAERS TYPE STRING,
BCOTM TYPE STRING,
ACOTM TYPE STRING,
BCTB1 TYPE STRING,
BCTB2 TYPE STRING,
BREGA TYPE STRING,
BCTBT TYPE STRING,
PRGAD TYPE STRING,
PCTBD TYPE STRING,
PRGBD TYPE STRING,
BRGTD TYPE STRING,
PBD75 TYPE STRING,
CMUNI TYPE STRING,END OF T_EKKO_STR. DATA: WA_PS0968_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_PS0968_STR-EMETH sy-vline
WA_PS0968_STR-EFILE sy-vline
WA_PS0968_STR-SSTAT sy-vline
WA_PS0968_STR-CSTAT sy-vline
WA_PS0968_STR-TIPOP sy-vline
WA_PS0968_STR-CDLUG sy-vline
WA_PS0968_STR-CNTRT sy-vline
WA_PS0968_STR-TRFCO sy-vline
WA_PS0968_STR-DIREC sy-vline
WA_PS0968_STR-VIAKM sy-vline
WA_PS0968_STR-OTROC sy-vline
WA_PS0968_STR-MUNIC sy-vline
WA_PS0968_STR-PROVN sy-vline
WA_PS0968_STR-CPAIS sy-vline
WA_PS0968_STR-CEMP2 sy-vline
WA_PS0968_STR-CTEP2 sy-vline
WA_PS0968_STR-CIFTY sy-vline
WA_PS0968_STR-CIFCO sy-vline
WA_PS0968_STR-RAZON sy-vline
WA_PS0968_STR-DMCIL sy-vline
WA_PS0968_STR-CPROV sy-vline
WA_PS0968_STR-CPOST sy-vline
WA_PS0968_STR-CTELE sy-vline
WA_PS0968_STR-CPLAN sy-vline
WA_PS0968_STR-FECAC sy-vline
WA_PS0968_STR-FECBA sy-vline
WA_PS0968_STR-HORAA sy-vline
WA_PS0968_STR-HTRAB sy-vline
WA_PS0968_STR-HABIT sy-vline
WA_PS0968_STR-EVALU sy-vline
WA_PS0968_STR-ADES1 sy-vline
WA_PS0968_STR-ADES2 sy-vline
WA_PS0968_STR-LUGAR sy-vline
WA_PS0968_STR-CDTRA sy-vline
WA_PS0968_STR-ESPEC sy-vline
WA_PS0968_STR-CDAGE sy-vline
WA_PS0968_STR-CDDES sy-vline
WA_PS0968_STR-AGENT sy-vline
WA_PS0968_STR-TPMOD sy-vline
WA_PS0968_STR-CDCON sy-vline
WA_PS0968_STR-AGENM sy-vline
WA_PS0968_STR-MULTI sy-vline
WA_PS0968_STR-TESTI sy-vline
WA_PS0968_STR-DATTE sy-vline
WA_PS0968_STR-CDLES sy-vline
WA_PS0968_STR-GRADO sy-vline
WA_PS0968_STR-CDPAR sy-vline
WA_PS0968_STR-MDNOM sy-vline
WA_PS0968_STR-MDDOM sy-vline
WA_PS0968_STR-MDTEL sy-vline
WA_PS0968_STR-ASIST sy-vline
WA_PS0968_STR-CDHOS sy-vline
WA_PS0968_STR-HOSPI sy-vline
WA_PS0968_STR-EPLAN sy-vline
WA_PS0968_STR-DTCCC sy-vline
WA_PS0968_STR-DCNAC sy-vline
WA_PS0968_STR-CDCNO sy-vline
WA_PS0968_STR-FENOM sy-vline
WA_PS0968_STR-FECAL sy-vline
WA_PS0968_STR-FEPRO sy-vline
WA_PS0968_STR-WAERS sy-vline
WA_PS0968_STR-BCOTM sy-vline
WA_PS0968_STR-ACOTM sy-vline
WA_PS0968_STR-BCTB1 sy-vline
WA_PS0968_STR-BCTB2 sy-vline
WA_PS0968_STR-BREGA sy-vline
WA_PS0968_STR-BCTBT sy-vline
WA_PS0968_STR-PRGAD sy-vline
WA_PS0968_STR-PCTBD sy-vline
WA_PS0968_STR-PRGBD sy-vline
WA_PS0968_STR-BRGTD sy-vline
WA_PS0968_STR-PBD75 sy-vline
WA_PS0968_STR-CMUNI sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.