ABAP Select data from SAP table P22_CEB 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 P22_CEB 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 P22_CEB. 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 P22_CEB 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_P22_CEB TYPE STANDARD TABLE OF P22_CEB, WA_P22_CEB TYPE P22_CEB, 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: <P22_CEB> TYPE P22_CEB. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_P22_CEB. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM P22_CEB INTO TABLE IT_P22_CEB. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM P22_CEB * INTO TABLE @DATA(IT_P22_CEB2). *--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_P22_CEB INDEX 1 INTO DATA(WA_P22_CEB2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_P22_CEB ASSIGNING <P22_CEB>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<P22_CEB>-PERNR = 1.
<P22_CEB>-ENAME = 1.
<P22_CEB>-BUKRS = 1.
<P22_CEB>-BUTXT = 1.
<P22_CEB>-WERKS = 1.
ENDLOOP. LOOP AT IT_P22_CEB INTO WA_P22_CEB. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_P22_CEB-PBTXT, sy-vline,
WA_P22_CEB-BTRTL, sy-vline,
WA_P22_CEB-BTRTX, sy-vline,
WA_P22_CEB-PERSG, sy-vline,
WA_P22_CEB-PGTXT, sy-vline,
WA_P22_CEB-PERSK, sy-vline.
ENDLOOP. *Add any further fields from structure WA_P22_CEB 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_P22_CEB 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_P22_CEB INTO WA_P22_CEB. *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 PDATE, internal->external for field GBDAT CALL FUNCTION 'CONVERSION_EXIT_PDATE_OUTPUT' EXPORTING input = WA_P22_CEB-GBDAT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_P22_CEB-GBDAT.
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_P22_CEB_STR,
PERNR TYPE STRING,
ENAME TYPE STRING,
BUKRS TYPE STRING,
BUTXT TYPE STRING,
WERKS TYPE STRING,
PBTXT TYPE STRING,
BTRTL TYPE STRING,
BTRTX TYPE STRING,
PERSG TYPE STRING,
PGTXT TYPE STRING,
PERSK TYPE STRING,
PKTXT TYPE STRING,
ORGEH TYPE STRING,
ORGTX TYPE STRING,
PLANS TYPE STRING,
PLSTX TYPE STRING,
GBDAT TYPE STRING,
NAME1 TYPE STRING,
NAME2 TYPE STRING,
SIINR TYPE STRING,
PAYM1 TYPE STRING,
SUBJ1 TYPE STRING,
BTAM1 TYPE STRING,
CUTD1 TYPE STRING,
SPCO1 TYPE STRING,
PLNW1 TYPE STRING,
PAYM2 TYPE STRING,
SUBJ2 TYPE STRING,
BTAM2 TYPE STRING,
CUTD2 TYPE STRING,
SPCO2 TYPE STRING,
PLNW2 TYPE STRING,
PAYM3 TYPE STRING,
SUBJ3 TYPE STRING,
BTAM3 TYPE STRING,
CUTD3 TYPE STRING,
SPCO3 TYPE STRING,
PLNW3 TYPE STRING,
JGSNM TYPE STRING,
LBINO TYPE STRING,
OFADR TYPE STRING,
JGNPS TYPE STRING,
JGNPR TYPE STRING,
RENAM TYPE STRING,
TBENF TYPE STRING,
SUBDT TYPE STRING,
ACQDT TYPE STRING,
WAERS TYPE STRING,
ABART TYPE STRING,
PAYDT TYPE STRING,
ENDDT TYPE STRING,
LTEXT TYPE STRING,
COMAL TYPE STRING,
WGFLG TYPE STRING,
OTELN TYPE STRING,
JURID TYPE STRING,
HWORK TYPE STRING,
NAMEO TYPE STRING,END OF T_EKKO_STR. DATA: WA_P22_CEB_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_P22_CEB_STR-PERNR sy-vline
WA_P22_CEB_STR-ENAME sy-vline
WA_P22_CEB_STR-BUKRS sy-vline
WA_P22_CEB_STR-BUTXT sy-vline
WA_P22_CEB_STR-WERKS sy-vline
WA_P22_CEB_STR-PBTXT sy-vline
WA_P22_CEB_STR-BTRTL sy-vline
WA_P22_CEB_STR-BTRTX sy-vline
WA_P22_CEB_STR-PERSG sy-vline
WA_P22_CEB_STR-PGTXT sy-vline
WA_P22_CEB_STR-PERSK sy-vline
WA_P22_CEB_STR-PKTXT sy-vline
WA_P22_CEB_STR-ORGEH sy-vline
WA_P22_CEB_STR-ORGTX sy-vline
WA_P22_CEB_STR-PLANS sy-vline
WA_P22_CEB_STR-PLSTX sy-vline
WA_P22_CEB_STR-GBDAT sy-vline
WA_P22_CEB_STR-NAME1 sy-vline
WA_P22_CEB_STR-NAME2 sy-vline
WA_P22_CEB_STR-SIINR sy-vline
WA_P22_CEB_STR-PAYM1 sy-vline
WA_P22_CEB_STR-SUBJ1 sy-vline
WA_P22_CEB_STR-BTAM1 sy-vline
WA_P22_CEB_STR-CUTD1 sy-vline
WA_P22_CEB_STR-SPCO1 sy-vline
WA_P22_CEB_STR-PLNW1 sy-vline
WA_P22_CEB_STR-PAYM2 sy-vline
WA_P22_CEB_STR-SUBJ2 sy-vline
WA_P22_CEB_STR-BTAM2 sy-vline
WA_P22_CEB_STR-CUTD2 sy-vline
WA_P22_CEB_STR-SPCO2 sy-vline
WA_P22_CEB_STR-PLNW2 sy-vline
WA_P22_CEB_STR-PAYM3 sy-vline
WA_P22_CEB_STR-SUBJ3 sy-vline
WA_P22_CEB_STR-BTAM3 sy-vline
WA_P22_CEB_STR-CUTD3 sy-vline
WA_P22_CEB_STR-SPCO3 sy-vline
WA_P22_CEB_STR-PLNW3 sy-vline
WA_P22_CEB_STR-JGSNM sy-vline
WA_P22_CEB_STR-LBINO sy-vline
WA_P22_CEB_STR-OFADR sy-vline
WA_P22_CEB_STR-JGNPS sy-vline
WA_P22_CEB_STR-JGNPR sy-vline
WA_P22_CEB_STR-RENAM sy-vline
WA_P22_CEB_STR-TBENF sy-vline
WA_P22_CEB_STR-SUBDT sy-vline
WA_P22_CEB_STR-ACQDT sy-vline
WA_P22_CEB_STR-WAERS sy-vline
WA_P22_CEB_STR-ABART sy-vline
WA_P22_CEB_STR-PAYDT sy-vline
WA_P22_CEB_STR-ENDDT sy-vline
WA_P22_CEB_STR-LTEXT sy-vline
WA_P22_CEB_STR-COMAL sy-vline
WA_P22_CEB_STR-WGFLG sy-vline
WA_P22_CEB_STR-OTELN sy-vline
WA_P22_CEB_STR-JURID sy-vline
WA_P22_CEB_STR-HWORK sy-vline
WA_P22_CEB_STR-NAMEO sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.