ABAP Select data from SAP table CKKVMK_PDCE 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 CKKVMK_PDCE 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 CKKVMK_PDCE. 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 CKKVMK_PDCE 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_CKKVMK_PDCE TYPE STANDARD TABLE OF CKKVMK_PDCE,
      WA_CKKVMK_PDCE TYPE CKKVMK_PDCE,
      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: <CKKVMK_PDCE> TYPE CKKVMK_PDCE.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_CKKVMK_PDCE.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM CKKVMK_PDCE
  INTO TABLE IT_CKKVMK_PDCE.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM CKKVMK_PDCE
*  INTO TABLE @DATA(IT_CKKVMK_PDCE2).
*--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_CKKVMK_PDCE INDEX 1 INTO DATA(WA_CKKVMK_PDCE2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_CKKVMK_PDCE ASSIGNING <CKKVMK_PDCE>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<CKKVMK_PDCE>-MANDT = 1.
<CKKVMK_PDCE>-KALAID = 1.
<CKKVMK_PDCE>-KALADAT = 1.
<CKKVMK_PDCE>-TVERS = 1.
<CKKVMK_PDCE>-KALST = 1.
ENDLOOP.

LOOP AT IT_CKKVMK_PDCE INTO WA_CKKVMK_PDCE.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_CKKVMK_PDCE-KALVZAE, sy-vline,
WA_CKKVMK_PDCE-DISST, sy-vline,
WA_CKKVMK_PDCE-CYCLENR, sy-vline,
WA_CKKVMK_PDCE-WERKS, sy-vline,
WA_CKKVMK_PDCE-MATNR, sy-vline,
WA_CKKVMK_PDCE-KALNR, sy-vline.
ENDLOOP. *Add any further fields from structure WA_CKKVMK_PDCE 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_CKKVMK_PDCE 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_CKKVMK_PDCE INTO WA_CKKVMK_PDCE. *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 MATN1, internal->external for field MATNR CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_CKKVMK_PDCE-MATNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CKKVMK_PDCE-MATNR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field VBELN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CKKVMK_PDCE-VBELN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CKKVMK_PDCE-VBELN.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ABPSP, internal->external for field PSPNR CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT' EXPORTING input = WA_CKKVMK_PDCE-PSPNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CKKVMK_PDCE-PSPNR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit NUMCV, internal->external for field STNUM CALL FUNCTION 'CONVERSION_EXIT_NUMCV_OUTPUT' EXPORTING input = WA_CKKVMK_PDCE-STNUM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CKKVMK_PDCE-STNUM.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field STALT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CKKVMK_PDCE-STALT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CKKVMK_PDCE-STALT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field PLNNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CKKVMK_PDCE-PLNNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CKKVMK_PDCE-PLNNR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field PLNAL CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CKKVMK_PDCE-PLNAL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CKKVMK_PDCE-PLNAL.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field MEINS CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_CKKVMK_PDCE-MEINS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CKKVMK_PDCE-MEINS.
WRITE:/ 'New Value:', ld_input.

*Conversion exit MATN1, internal->external for field TYPE CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_CKKVMK_PDCE-TYPE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CKKVMK_PDCE-TYPE.
WRITE:/ 'New Value:', ld_input.

*Conversion exit MATN1, internal->external for field PROZESS CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_CKKVMK_PDCE-PROZESS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CKKVMK_PDCE-PROZESS.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field PR_MEINS CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_CKKVMK_PDCE-PR_MEINS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CKKVMK_PDCE-PR_MEINS.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field PRCTR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CKKVMK_PDCE-PRCTR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CKKVMK_PDCE-PRCTR.
WRITE:/ 'New Value:', ld_input.

*Conversion exit MATN1, internal->external for field INP_IN_PROC CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_CKKVMK_PDCE-INP_IN_PROC IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CKKVMK_PDCE-INP_IN_PROC.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field SCNAM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_CKKVMK_PDCE-SCNAM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_CKKVMK_PDCE-SCNAM.
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_CKKVMK_PDCE_STR,
MANDT TYPE STRING,
KALAID TYPE STRING,
KALADAT TYPE STRING,
TVERS TYPE STRING,
KALST TYPE STRING,
KALVZAE TYPE STRING,
DISST TYPE STRING,
CYCLENR TYPE STRING,
WERKS TYPE STRING,
MATNR TYPE STRING,
KALNR TYPE STRING,
BWTAR TYPE STRING,
VERID TYPE STRING,
VBELN TYPE STRING,
POSNR TYPE STRING,
PSPNR TYPE STRING,
STLAN TYPE STRING,
STNUM TYPE STRING,
STALT TYPE STRING,
STVFIX TYPE STRING,
ALTSL TYPE STRING,
PLNTY TYPE STRING,
PLNNR TYPE STRING,
PLNAL TYPE STRING,
PLNCT TYPE STRING,
LOSGR TYPE STRING,
SUMLO TYPE STRING,
LOSAU TYPE STRING,
AUSSS TYPE STRING,
MEINS TYPE STRING,
KADAT TYPE STRING,
BIDAT TYPE STRING,
ALDAT TYPE STRING,
BEDAT TYPE STRING,
BWDAT TYPE STRING,
FEH_A_ANZ TYPE STRING,
FEH_K_ANZ TYPE STRING,
FEH_STATUS TYPE STRING,
FEH_STATUF TYPE STRING,
DISPO TYPE STRING,
EKGRP TYPE STRING,
LABOR TYPE STRING,
VAGRP TYPE STRING,
SOBSL TYPE STRING,
SOBES TYPE STRING,
SOWRK TYPE STRING,
SODUM TYPE STRING,
SBDKZ TYPE STRING,
BESKZ TYPE STRING,
KOSGR TYPE STRING,
ZSCHL TYPE STRING,
CUOBJ TYPE STRING,
CUOBJID TYPE STRING,
TYPE TYPE STRING,
WRKLT TYPE STRING,
PROZESS TYPE STRING,
KZKUP TYPE STRING,
FXPRU TYPE STRING,
PR_LOSGR TYPE STRING,
PR_SUMLO TYPE STRING,
PR_LOSAU TYPE STRING,
PR_MEINS TYPE STRING,
PR_VERID TYPE STRING,
MLMAA TYPE STRING,
ERFNM TYPE STRING,
ROHSTOFF TYPE STRING,
PRCTR TYPE STRING,
SPART TYPE STRING,
MTART TYPE STRING,
BALTKZ TYPE STRING,
KALNR_BA TYPE STRING,
MKALK TYPE STRING,
BTYP TYPE STRING,
SUMMENSATZ TYPE STRING,
NEZDISST TYPE STRING,
NEZDISST_CYCLE TYPE STRING,
FIRST_KEKO TYPE STRING,
LAST_KEKO TYPE STRING,
PTR_SUM TYPE STRING,
SPERRKZ TYPE STRING,
LOSMA TYPE STRING,
VORGAENGER TYPE STRING,
STUEAUF TYPE STRING,
STRUNR TYPE STRING,
MNGLG TYPE STRING,
SBDKZ_KOPF TYPE STRING,
KALNR_TOP TYPE STRING,
STLKN TYPE STRING,
BEZWISSEN TYPE STRING,
INP_IN_PROC TYPE STRING,
PATNR TYPE STRING,
AUSID TYPE STRING,
CFXPR TYPE STRING,
CSPLIT TYPE STRING,
ZIFFR TYPE STRING,
SUMZIFFR TYPE STRING,
SCNAM TYPE STRING,
AFAKT TYPE STRING,
DBREAD TYPE STRING,
SELKZ TYPE STRING,
LOSGR_INPUT TYPE STRING,
PEINH TYPE STRING,
BALT_INPUT TYPE STRING,
OTYP TYPE STRING,
NO_UNITCOSTING TYPE STRING,
KZEFF TYPE STRING,
MAXMSGTYP TYPE STRING,
MISCH_VERH TYPE STRING,
MGTYP TYPE STRING,
BWVAR_BA TYPE STRING,
PLSCN TYPE STRING,
PLMNG TYPE STRING,END OF T_EKKO_STR. DATA: WA_CKKVMK_PDCE_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_CKKVMK_PDCE_STR-MANDT sy-vline
WA_CKKVMK_PDCE_STR-KALAID sy-vline
WA_CKKVMK_PDCE_STR-KALADAT sy-vline
WA_CKKVMK_PDCE_STR-TVERS sy-vline
WA_CKKVMK_PDCE_STR-KALST sy-vline
WA_CKKVMK_PDCE_STR-KALVZAE sy-vline
WA_CKKVMK_PDCE_STR-DISST sy-vline
WA_CKKVMK_PDCE_STR-CYCLENR sy-vline
WA_CKKVMK_PDCE_STR-WERKS sy-vline
WA_CKKVMK_PDCE_STR-MATNR sy-vline
WA_CKKVMK_PDCE_STR-KALNR sy-vline
WA_CKKVMK_PDCE_STR-BWTAR sy-vline
WA_CKKVMK_PDCE_STR-VERID sy-vline
WA_CKKVMK_PDCE_STR-VBELN sy-vline
WA_CKKVMK_PDCE_STR-POSNR sy-vline
WA_CKKVMK_PDCE_STR-PSPNR sy-vline
WA_CKKVMK_PDCE_STR-STLAN sy-vline
WA_CKKVMK_PDCE_STR-STNUM sy-vline
WA_CKKVMK_PDCE_STR-STALT sy-vline
WA_CKKVMK_PDCE_STR-STVFIX sy-vline
WA_CKKVMK_PDCE_STR-ALTSL sy-vline
WA_CKKVMK_PDCE_STR-PLNTY sy-vline
WA_CKKVMK_PDCE_STR-PLNNR sy-vline
WA_CKKVMK_PDCE_STR-PLNAL sy-vline
WA_CKKVMK_PDCE_STR-PLNCT sy-vline
WA_CKKVMK_PDCE_STR-LOSGR sy-vline
WA_CKKVMK_PDCE_STR-SUMLO sy-vline
WA_CKKVMK_PDCE_STR-LOSAU sy-vline
WA_CKKVMK_PDCE_STR-AUSSS sy-vline
WA_CKKVMK_PDCE_STR-MEINS sy-vline
WA_CKKVMK_PDCE_STR-KADAT sy-vline
WA_CKKVMK_PDCE_STR-BIDAT sy-vline
WA_CKKVMK_PDCE_STR-ALDAT sy-vline
WA_CKKVMK_PDCE_STR-BEDAT sy-vline
WA_CKKVMK_PDCE_STR-BWDAT sy-vline
WA_CKKVMK_PDCE_STR-FEH_A_ANZ sy-vline
WA_CKKVMK_PDCE_STR-FEH_K_ANZ sy-vline
WA_CKKVMK_PDCE_STR-FEH_STATUS sy-vline
WA_CKKVMK_PDCE_STR-FEH_STATUF sy-vline
WA_CKKVMK_PDCE_STR-DISPO sy-vline
WA_CKKVMK_PDCE_STR-EKGRP sy-vline
WA_CKKVMK_PDCE_STR-LABOR sy-vline
WA_CKKVMK_PDCE_STR-VAGRP sy-vline
WA_CKKVMK_PDCE_STR-SOBSL sy-vline
WA_CKKVMK_PDCE_STR-SOBES sy-vline
WA_CKKVMK_PDCE_STR-SOWRK sy-vline
WA_CKKVMK_PDCE_STR-SODUM sy-vline
WA_CKKVMK_PDCE_STR-SBDKZ sy-vline
WA_CKKVMK_PDCE_STR-BESKZ sy-vline
WA_CKKVMK_PDCE_STR-KOSGR sy-vline
WA_CKKVMK_PDCE_STR-ZSCHL sy-vline
WA_CKKVMK_PDCE_STR-CUOBJ sy-vline
WA_CKKVMK_PDCE_STR-CUOBJID sy-vline
WA_CKKVMK_PDCE_STR-TYPE sy-vline
WA_CKKVMK_PDCE_STR-WRKLT sy-vline
WA_CKKVMK_PDCE_STR-PROZESS sy-vline
WA_CKKVMK_PDCE_STR-KZKUP sy-vline
WA_CKKVMK_PDCE_STR-FXPRU sy-vline
WA_CKKVMK_PDCE_STR-PR_LOSGR sy-vline
WA_CKKVMK_PDCE_STR-PR_SUMLO sy-vline
WA_CKKVMK_PDCE_STR-PR_LOSAU sy-vline
WA_CKKVMK_PDCE_STR-PR_MEINS sy-vline
WA_CKKVMK_PDCE_STR-PR_VERID sy-vline
WA_CKKVMK_PDCE_STR-MLMAA sy-vline
WA_CKKVMK_PDCE_STR-ERFNM sy-vline
WA_CKKVMK_PDCE_STR-ROHSTOFF sy-vline
WA_CKKVMK_PDCE_STR-PRCTR sy-vline
WA_CKKVMK_PDCE_STR-SPART sy-vline
WA_CKKVMK_PDCE_STR-MTART sy-vline
WA_CKKVMK_PDCE_STR-BALTKZ sy-vline
WA_CKKVMK_PDCE_STR-KALNR_BA sy-vline
WA_CKKVMK_PDCE_STR-MKALK sy-vline
WA_CKKVMK_PDCE_STR-BTYP sy-vline
WA_CKKVMK_PDCE_STR-SUMMENSATZ sy-vline
WA_CKKVMK_PDCE_STR-NEZDISST sy-vline
WA_CKKVMK_PDCE_STR-NEZDISST_CYCLE sy-vline
WA_CKKVMK_PDCE_STR-FIRST_KEKO sy-vline
WA_CKKVMK_PDCE_STR-LAST_KEKO sy-vline
WA_CKKVMK_PDCE_STR-PTR_SUM sy-vline
WA_CKKVMK_PDCE_STR-SPERRKZ sy-vline
WA_CKKVMK_PDCE_STR-LOSMA sy-vline
WA_CKKVMK_PDCE_STR-VORGAENGER sy-vline
WA_CKKVMK_PDCE_STR-STUEAUF sy-vline
WA_CKKVMK_PDCE_STR-STRUNR sy-vline
WA_CKKVMK_PDCE_STR-MNGLG sy-vline
WA_CKKVMK_PDCE_STR-SBDKZ_KOPF sy-vline
WA_CKKVMK_PDCE_STR-KALNR_TOP sy-vline
WA_CKKVMK_PDCE_STR-STLKN sy-vline
WA_CKKVMK_PDCE_STR-BEZWISSEN sy-vline
WA_CKKVMK_PDCE_STR-INP_IN_PROC sy-vline
WA_CKKVMK_PDCE_STR-PATNR sy-vline
WA_CKKVMK_PDCE_STR-AUSID sy-vline
WA_CKKVMK_PDCE_STR-CFXPR sy-vline
WA_CKKVMK_PDCE_STR-CSPLIT sy-vline
WA_CKKVMK_PDCE_STR-ZIFFR sy-vline
WA_CKKVMK_PDCE_STR-SUMZIFFR sy-vline
WA_CKKVMK_PDCE_STR-SCNAM sy-vline
WA_CKKVMK_PDCE_STR-AFAKT sy-vline
WA_CKKVMK_PDCE_STR-DBREAD sy-vline
WA_CKKVMK_PDCE_STR-SELKZ sy-vline
WA_CKKVMK_PDCE_STR-LOSGR_INPUT sy-vline
WA_CKKVMK_PDCE_STR-PEINH sy-vline
WA_CKKVMK_PDCE_STR-BALT_INPUT sy-vline
WA_CKKVMK_PDCE_STR-OTYP sy-vline
WA_CKKVMK_PDCE_STR-NO_UNITCOSTING sy-vline
WA_CKKVMK_PDCE_STR-KZEFF sy-vline
WA_CKKVMK_PDCE_STR-MAXMSGTYP sy-vline
WA_CKKVMK_PDCE_STR-MISCH_VERH sy-vline
WA_CKKVMK_PDCE_STR-MGTYP sy-vline
WA_CKKVMK_PDCE_STR-BWVAR_BA sy-vline
WA_CKKVMK_PDCE_STR-PLSCN sy-vline
WA_CKKVMK_PDCE_STR-PLMNG sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.