Friday, June 19, 2015

#SAP #ABAP Testing a function module without creating a program

It's an usual activity during the implementation of an extension, the research of bapi(s) that performs the execution of the business process or task , and the best way to confirm if this is the right one is performing a test.  However when you test it using the tcode SE37, you cannot check the behavior unless you commit the process.  At this point, usually we go to the SE38 in order to create a new test program.

Rather than creating a new program you can use this functionality:

Una actividad habitual durante la implementación de una extensión, es la investigación de bapi (s) que puedan llevar a cabo la ejecución de los procesos de negocio o tareas, y la mejor manera de confirmar si una es el más adecuada es realizando una prueba. Sin embargo cuando se prueba utilizando la SE37, no se puede comprobar el comportamiento a menos que se ejecute un commit en la base de datos.  En este momento usualmente nos vamos a la se38 y creamos un pequeño programa para hacer la prueba.

En lugar de crear un nuevo programa podemos utlizar esta funcionalidad no muy publicitada:


1.- Go to tcode SE37

2.- Menu Function Module -> Execute -> Test Sequences

3.- Enter your function modules and at the end BAPI_TRANSACTION_COMMIT.



















4.-Execute

You'll be able to test your function modules one after the other.

Hope be useful!


Regards,

By Jose Antonio Lagonell

Thursday, June 11, 2015

SAP ABAP - Sending a message (email) to the business workplace

This post will let you know how coding the call to the FM SO_NEW_DOCUMENT_SEND_API1 in order to be able to send a message to a business workplace.  If you want to send a message to an internet mail, just change the rec_type and make sure that all the proper configuration is done in transaction SCOT.  Email sent to external addresses can be viewed on TCODE SOST.
-----------------------------------------------------------------------------------------------------------------
Este post le permitirá saber cómo codificar la llamada a la funcion SO_NEW_DOCUMENT_SEND_API1  con el fin de enviar un mensaje al business workplace de un SAP user. Si desea enviar un mensaje a un correo de Internet, basta con cambiar el valor de rec_type y asegúrese de que toda la configuración adecuada se realiza en la SCOT. El correo electrónico enviado a direcciones externas se puede ver en la transaccion  SOST.

Here a the sample ABAP code/ Aquí un código ABAP la muestra:


**************************
* SEND RESULTS
**************************
    clear : maildata, mailtxt, mailrec.
    refresh:mailtxt, mailrec.

    maildata-obj_name = 'Mail Name'.
    maildata-obj_descr = 'Mail description'.
    maildata-obj_langu = sy-langu.

    concatenate 'Message:' lv_data into mailtxt-line.
    append mailtxt.
    loop at it_table_data into wa_table_data.
      mailtxt-line = wa_table_data-text.
      append mailtxt.
    endloop.

    mailrec-receiver = sy-uname.
    mailrec-rec_type = 'B'.
    append mailrec.

    CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
      EXPORTING
        document_data              = maildata
        DOCUMENT_TYPE              = 'RAW'
        PUT_IN_OUTBOX              = ' '
        COMMIT_WORK                = 'X'
*      IMPORTING
*       SENT_TO_ALL                =
*       NEW_OBJECT_ID              =
      tables
        OBJECT_HEADER              = mailtxt
        OBJECT_CONTENT             = mailtxt
*       CONTENTS_HEX               =
*       OBJECT_PARA                =
*       OBJECT_PARB                =
        receivers                  = mailrec
      EXCEPTIONS
        TOO_MANY_RECEIVERS         = 1
        DOCUMENT_NOT_SENT          = 2
        DOCUMENT_TYPE_NOT_EXIST    = 3
        OPERATION_NO_AUTHORIZATION = 4
        PARAMETER_ERROR            = 5
        X_ERROR                    = 6
        ENQUEUE_ERROR              = 7
        OTHERS                     = 8.
  ENDIF.

If you find this useful, please do not hesitate in like and share it!

Friday, June 5, 2015

WEB PHP: How to know if I have php on my web server

Now I'm starting in web development world, I've just purchased the domain www.good-to-share.com and my first question was what language to use? Thanks to my friend Daniel Durand (almost the venezuelan GOD of php) I'm thinking seriously in use it to make some developments, so here my first question: Do I have php?

Here the code that answers this question:

<html>
  <head>
    <title>Check php Version on this server</title>
  </head>
  <body>

<?php

phpinfo();

?>
  </body>
</html>

Just create a file you can call version.php, place it on your website and type it on the url field: www.yourdomain.com/version.php

You'll know if you have it!

---------------------------------------

Ahora que estoy empezando en el mundo del desarrollo web, acabo de comprar el dominio www.good-to-share.com y mi primera pregunta era qué lenguaje usar? Gracias a mi amigo Daniel Durand (casi el DIOS venezolano de php) Estoy pensando seriamente en usarlo para desarrollar, asi que aquí mi primera pregunta: ¿Tengo php?

Aquí el código que responde a esta pregunta:

<html>
  <head>
    <title>Check php Version on this server</title>
  </head>
  <body>

<?php

phpinfo();

?>
  </body>
</html>

Basta con crear un archivo que puede llamarse version.php, colocarlo en su sitio web y escríba en el  url: www.yourdomain.com/version.php

Asi  sabrás si lo tienes!

By Jose Antonio Lagonell

Tuesday, June 2, 2015

SAP ABAP: How to check if an object is locked

Usually during a program/fm development we need to use multiple function modules, bapi's or call transaction in order to complete a whole customer process, for instance customer creation + sales order creation, or unpacking a HU into an outbound delivery and unblocking it for further processing.

Between the function calls we should wait until the object is released by the previous logic unit. Over there we can find solutions like "wait" instruction and also the function module "ENQUEUE_REPORT" which let us know what is locked for the moment this FM is ran.

Following  a sample code to determine if a sales document is locked:

  lv_repeat = 'Y'.
  while lv_repeat = 'Y'.
    CALL FUNCTION 'ENQUEUE_REPORT'
      EXPORTING
        GCLIENT               = SY-MANDT
        GNAME                 = ' '
        GTARG                 = ' '
        GUNAME                = SY-UNAME
      IMPORTING
        NUMBER                = lv_number
        SUBRC                 = lv_subrc
      TABLES
        ENQ                   = lt_enq
      EXCEPTIONS
        COMMUNICATION_FAILURE = 1
        SYSTEM_FAILURE        = 2
        OTHERS                = 3.

    concatenate sy-mandt p_vbeln into lv_key.
    read table lt_enq with key garg = lv_key transporting no fields.
    if sy-subrc = 0. "if found the object is locked yet
      lv_repeat = 'Y'.
    else.
      lv_repeat = 'N'.
    endif.
  endwhile.

If you find this useful, please do not hesitate in like and share it!
-------------------------------------------------------------------------------------------------------
Por lo general, durante la construccion de un  programa o modulo de funciones tenemos que utilizar múltiples FM, BAPI's o call transactions con el fin de completar un proceso cliente. Por ejemplo la creación de un cliente + orden de venta, o desempaquetar un unidad de empaque en una entrega de salida y desbloqueo para su posterior procesamiento.

Entre las llamadas a funciones que deberíamos esperar hasta que el objeto es liberado por la unidad lógica anterior. Allí podemos encontrar soluciones como usar la instruccion "wait"  y también el módulo de función "ENQUEUE_REPORT", que nos dice lo que está bloqueado al momento de su ejecucion.

A continuacion código de ejemplo para determinar si un documento de ventas está bloqueado:

  lv_repeat = 'Y'.
  while lv_repeat = 'Y'.
    CALL FUNCTION 'ENQUEUE_REPORT'
      EXPORTING
        GCLIENT               = SY-MANDT
        GNAME                 = ' '
        GTARG                 = ' '
        GUNAME                = SY-UNAME
      IMPORTING
        NUMBER                = lv_number
        SUBRC                 = lv_subrc
      TABLES
        ENQ                   = lt_enq
      EXCEPTIONS
        COMMUNICATION_FAILURE = 1
        SYSTEM_FAILURE        = 2
        OTHERS                = 3.

    concatenate sy-mandt p_vbeln into lv_key.
    read table lt_enq with key garg = lv_key transporting no fields.
    if sy-subrc = 0. "if found the object is locked yet
      lv_repeat = 'Y'.
    else.
      lv_repeat = 'N'.
    endif.
  endwhile.

Si encuentras este post util, por favor no dudes en darle "like" o compartirlo!

By Jose Antonio Lagonell


Monday, June 1, 2015

SAP ABAP: Minus sign to the left

Sometimes, we need output number values to reports or ALV's, although there are several ways to do it, here a function module that does the work:

        CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
          CHANGING             VALUE type_c_amount.



Hope be helpful for you!
----------------------------------------
A veces tenemos que formatear la salida para valores numéricos en reportes o ALV's, aunque hay varias maneras de hacerlo, aquí encontré un módulo de funciones que pone al menos el signo "-" primero:

         FUNCIÓN DE LLAMADA 'CLOI_PUT_SIGN_IN_FRONT'
           CAMBIO
             VALOR = type_c_amount.

Espero que sea te sea util!

Python - borrar lineas extra de archivos .txt en un directorio

 Aqui el codigo Python para borrar lineas extra en un archivo plano: import os path = "c:\\temp" path_new='c:\\temp\\CleanFile...